< previous page page_448 next page >

Page 448
In the Employees class, youll find a Collection class declared in the General Declarations area of the class module:
9f31265bb40b592b1929e18a47ab28e5.gif
Private mcolEmps As Collection
Of course, youll need to create a new instance of this Collection class. This you can do in the Class_Initialize() event, like this:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub Class_Initialize()
   Set mcolEmps = New Collection
End Sub
Youll find an Add method in this class, but it does not accept objects. Instead, it only accepts EmployeeID, FirstName, LastName, and Salary values. This forces you to pass in employee data only, not just any data type you want:
9f31265bb40b592b1929e18a47ab28e5.gif
Public Function Add(ByVal EmpID As Long, _
                    ByVal FirstName As String, _
                    ByVal LastName As String, _
                    ByVal Salary As Currency) As Employee

   Dim oEmp As Employee

   Set oEmp = New Employee
   ' Load Properties of New Class
   With oEmp
      .EmpID = EmpID
      .FirstName = FirstName
      .LastName = LastName
      .Salary = Salary
   End With

   ' Add To Private Collection
   mcolEmps.Add oEmp, CStr(EmpID)

   Set Add = oEmp
End Function
In the Add method, you create a new Employee object, fill in the properties from the arguments passed to this method, and then add the Employee object to the private collection in this class. Its customary to return the newly created Employee object from the Add method, so thats what you should do in your Add method as well.

 
< previous page page_448 next page >

If you like this book, buy it!